#include <stdlib.h>

#include "linkedlist.h"
#include "linkedqueue.h"

/*
 * Structure declarations
 */

struct linkedqueue_adt {
	LinkedList list;
	int count;
};

/*
 * Public functions
 */

LinkedQueue LQ_New() {
	LinkedQueue result;
	
	result = (LinkedQueue) malloc(sizeof(struct linkedqueue_adt));
	
	result->list = LL_New();
	result->count = 0;
	
	return result;
}

void LQ_Free(LinkedQueue queue) {
	if (queue == NULL)
		return;
	
	LL_Free(queue->list);
	
	free(queue);
}

int LQ_Size(LinkedQueue queue) {
	if (queue == NULL)
		return -1;
	
	return queue->count;
}

int LQ_Empty(LinkedQueue queue) {
	if (queue == NULL)
		return -1;
	
	return (queue->count == 0) ? 1 : 0;
}

void LQ_Enqueue(LinkedQueue queue, void *el) {
	if (queue == NULL)
		return;
	
	LL_Add(queue->list, LL_End(queue->list), el);
	
	queue->count++;
}

void LQ_Dequeue(LinkedQueue queue) {
	if (queue == NULL || queue->count == 0)
		return;
	
	LL_Remove(queue->list, LL_Begin(queue->list));
	
	queue->count--;
}

void *LQ_Front(LinkedQueue queue) {
	if (queue == NULL || queue->count == 0)
		return NULL;
	
	return LL_Get(queue->list, LL_Begin(queue->list));
}
